import * as Blockly from 'blockly/core'
import { Profile } from 'mixly'

Profile = Profile?.default ? Profile : window.profile

export const sentry_index_objs = function () {
    return [
        ['#1', '1'],
        ['#2', '2'],
        ['#3', '3'],
        ['#4', '4'],
        ['#5', '5'],
    ]
}

export const vision_res_objs = function () {
    return [
        [Blockly.Msg.SENTRY3_STATE_VALUE_X, 'kXValue'],
        [Blockly.Msg.SENTRY3_STATE_VALUE_Y, 'kYValue'],
        [Blockly.Msg.SENTRY3_STATE_VALUE_WIDTH, 'kWidthValue'],
        [Blockly.Msg.SENTRY3_STATE_VALUE_HEIGHT, 'kHeightValue'],
        [Blockly.Msg.SENTRY3_STATE_VALUE_LABEL, 'kLabel'],
    ]
}

export const vision_custom_objs = function () {
    return [
        [Blockly.Msg.SENTRY3_VISION_DATA + '1', 'kXValue'],
        [Blockly.Msg.SENTRY3_VISION_DATA + '2', 'kYValue'],
        [Blockly.Msg.SENTRY3_VISION_DATA + '3', 'kWidthValue'],
        [Blockly.Msg.SENTRY3_VISION_DATA + '4', 'kHeightValue'],
        [Blockly.Msg.SENTRY3_VISION_DATA + '5', 'kLabel'],
    ]
}

export const vision_qr_objs = function () {
    return [
        [Blockly.Msg.SENTRY3_STATE_VALUE_X, 'kXValue'],
        [Blockly.Msg.SENTRY3_STATE_VALUE_Y, 'kYValue'],
        [Blockly.Msg.SENTRY3_STATE_VALUE_WIDTH, 'kWidthValue'],
        [Blockly.Msg.SENTRY3_STATE_VALUE_HEIGHT, 'kHeightValue'],
    ]
}

export const vision_color_objs = function () {
    return [
        [Blockly.Msg.SENTRY3_STATE_VALUE_LABEL, 'kLabel'],
        [Blockly.Msg.SENTRY3_STATE_VALUE_R, 'kRValue'],
        [Blockly.Msg.SENTRY3_STATE_VALUE_G, 'kGValue'],
        [Blockly.Msg.SENTRY3_STATE_VALUE_B, 'kBValue'],
    ]
}
export const vision_line_objs = function () {
    return [
        [Blockly.Msg.SENTRY3_STATE_LINE_EX, 'kXValue'],
        [Blockly.Msg.SENTRY3_STATE_LINE_EY, 'kYValue'],
        [Blockly.Msg.SENTRY3_STATE_LINE_SX, 'kWidthValue'],
        [Blockly.Msg.SENTRY3_STATE_LINE_SY, 'kHeightValue'],
        [Blockly.Msg.SENTRY3_STATE_LINE_A, 'kLabel'],
    ]
}

export const sentry3_vision_blod_objs = function () {
    return [
        [Blockly.Msg.SENTRY3_COLOR_BLACK, 'Sentry3::kColorBlack'],
        [Blockly.Msg.SENTRY3_COLOR_WHITE, 'Sentry3::kColorWhite'],
        [Blockly.Msg.SENTRY3_COLOR_RED, 'Sentry3::kColorRed'],
        [Blockly.Msg.SENTRY3_COLOR_GREEN, 'Sentry3::kColorGreen'],
        [Blockly.Msg.SENTRY3_COLOR_BLUE, 'Sentry3::kColorBlue'],
        [Blockly.Msg.SENTRY3_COLOR_YELLOW, 'Sentry3::kColorYellow'],
    ]
}
export const sentry3_vision_objs = function () {
    return [
        [Blockly.Msg.SENTRY3_VISION_VISIONCOLOR, 'Sentry3::kVisionColor'],
        [Blockly.Msg.SENTRY3_VISION_VISIONBLOB, 'Sentry3::kVisionBlob'],
        [Blockly.Msg.SENTRY3_VISION_VISIONAPRILTAG, 'Sentry3::kVisionAprilTag'],
        [Blockly.Msg.SENTRY3_VISION_VISIONLINE, 'Sentry3::kVisionLine'],
        [Blockly.Msg.SENTRY3_VISION_VISIONLEARNING, 'Sentry3::kVisionLearning'],
        [Blockly.Msg.SENTRY3_VISION_VISIONFACE, 'Sentry3::kVisionFace'],
        [
            Blockly.Msg.SENTRY3_VISION_VISIONYOLO,
            'Sentry3::kVisionYolo',
        ],
        [Blockly.Msg.SENTRY3_VISION_VISIONQRCODE, 'Sentry3::kVisionQrCode'],
        [Blockly.Msg.SENTRY3_VISION_VISIONBARCODE, 'Sentry3::kVisionBarCode'],
        [Blockly.Msg.SENTRY3_VISION_VISIONOCR, 'Sentry3::kVisionOCR'],
        [Blockly.Msg.SENTRY3_VISION_VISIONHANDGESTURE, 'Sentry3::kVisionHandPose'],
        [Blockly.Msg.SENTRY3_VISION_VISIONLICENCEPLATE, 'Sentry3::kVisionLicensePlate'],

    ]
}

export const sentry3_vision_param_objs = function () {
    return [
        [Blockly.Msg.SENTRY3_VISION_VISIONCOLOR, 'Sentry3::kVisionColor'],
        [Blockly.Msg.SENTRY3_VISION_VISIONBLOB, 'Sentry3::kVisionBlob'],
    ]
}
export const sentry3_vision_custom = function () {
    return [
        [Blockly.Msg.SENTRY3_VISION_VISIONLEARNING, 'Sentry3::kVisionLearning'],
        [Blockly.Msg.SENTRY3_VISION_VISIONFACE, 'Sentry3::kVisionFace'],
    ]
}
export const sentry3_vision_yolo_objs = function () {
    return [
        [Blockly.Msg.SENTRY3_YOLO_PERSON, 'Sentry3::kPerson'],
        [Blockly.Msg.SENTRY3_YOLO_BICYCLE, 'Sentry3::kBicycle'],
        [Blockly.Msg.SENTRY3_YOLO_CAR, 'Sentry3::kCar'],
        [Blockly.Msg.SENTRY3_YOLO_MOTORCYCLE, 'Sentry3::kMotorcycle'],
        [Blockly.Msg.SENTRY3_YOLO_AIRPLANE, 'Sentry3::kAirplane'],
        [Blockly.Msg.SENTRY3_YOLO_BUS, 'Sentry3::kBus'],
        [Blockly.Msg.SENTRY3_YOLO_TRAIN, 'Sentry3::kTrain'],
        [Blockly.Msg.SENTRY3_YOLO_TRUCK, 'Sentry3::kTruck'],
        [Blockly.Msg.SENTRY3_YOLO_BOAT, 'Sentry3::kBoat'],
        [Blockly.Msg.SENTRY3_YOLO_TRAFFIC_LIGHT, 'Sentry3::kTrafficLight'],
        [Blockly.Msg.SENTRY3_YOLO_FIRE_HYDRANT, 'Sentry3::kFireHydrant'],
        [Blockly.Msg.SENTRY3_YOLO_STOP_SIGN, 'Sentry3::kStopSign'],
        [Blockly.Msg.SENTRY3_YOLO_PARKING_METER, 'Sentry3::kParkingMeter'],
        [Blockly.Msg.SENTRY3_YOLO_BENCH, 'Sentry3::kBench'],
        [Blockly.Msg.SENTRY3_YOLO_BIRD, 'Sentry3::kBird'],
        [Blockly.Msg.SENTRY3_YOLO_CAT, 'Sentry3::kCat'],
        [Blockly.Msg.SENTRY3_YOLO_DOG, 'Sentry3::kDog'],
        [Blockly.Msg.SENTRY3_YOLO_HORSE, 'Sentry3::kHorse'],
        [Blockly.Msg.SENTRY3_YOLO_SHEEP, 'Sentry3::kSheep'],
        [Blockly.Msg.SENTRY3_YOLO_COW, 'Sentry3::kCow'],
        [Blockly.Msg.SENTRY3_YOLO_ELEPHANT, 'Sentry3::kElephant'],
        [Blockly.Msg.SENTRY3_YOLO_BEAR, 'Sentry3::kBear'],
        [Blockly.Msg.SENTRY3_YOLO_ZEBRA, 'Sentry3::kZebra'],
        [Blockly.Msg.SENTRY3_YOLO_GIRAFFE, 'Sentry3::kGiraffe'],
        [Blockly.Msg.SENTRY3_YOLO_BACKPACK, 'Sentry3::kBackpack'],
        [Blockly.Msg.SENTRY3_YOLO_UMBRELLA, 'Sentry3::kUmbrella'],
        [Blockly.Msg.SENTRY3_YOLO_HANDBAG, 'Sentry3::kHandbag'],
        [Blockly.Msg.SENTRY3_YOLO_TIE, 'Sentry3::kTie'],
        [Blockly.Msg.SENTRY3_YOLO_SUITCASE, 'Sentry3::kSuitcase'],
        [Blockly.Msg.SENTRY3_YOLO_FRISBEE, 'Sentry3::kFrisbee'],
        [Blockly.Msg.SENTRY3_YOLO_SKIS, 'Sentry3::kSkis'],
        [Blockly.Msg.SENTRY3_YOLO_SNOWBOARD, 'Sentry3::kSnowboard'],
        [Blockly.Msg.SENTRY3_YOLO_SPORTS_BALL, 'Sentry3::kSportsBall'],
        [Blockly.Msg.SENTRY3_YOLO_KITE, 'Sentry3::kKite'],
        [Blockly.Msg.SENTRY3_YOLO_BASEBALL_BAT, 'Sentry3::kBaseballBat'],
        [Blockly.Msg.SENTRY3_YOLO_BASEBALL_GLOVE, 'Sentry3::kBaseballGlove'],
        [Blockly.Msg.SENTRY3_YOLO_SKATEBOARD, 'Sentry3::kSkateboard'],
        [Blockly.Msg.SENTRY3_YOLO_SURFBOARD, 'Sentry3::kSurfboard'],
        [Blockly.Msg.SENTRY3_YOLO_TENNIS_RACKET, 'Sentry3::kTennisRacket'],
        [Blockly.Msg.SENTRY3_YOLO_BOTTLE, 'Sentry3::kBottle'],
        [Blockly.Msg.SENTRY3_YOLO_WINE_GLASS, 'Sentry3::kWineGlass'],
        [Blockly.Msg.SENTRY3_YOLO_CUP, 'Sentry3::kCup'],
        [Blockly.Msg.SENTRY3_YOLO_FORK, 'Sentry3::kFork'],
        [Blockly.Msg.SENTRY3_YOLO_KNIFE, 'Sentry3::kKnife'],
        [Blockly.Msg.SENTRY3_YOLO_SPOON, 'Sentry3::kSpoon'],
        [Blockly.Msg.SENTRY3_YOLO_BOWL, 'Sentry3::kBowl'],
        [Blockly.Msg.SENTRY3_YOLO_BANANA, 'Sentry3::kBanana'],
        [Blockly.Msg.SENTRY3_YOLO_APPLE, 'Sentry3::kApple'],
        [Blockly.Msg.SENTRY3_YOLO_SANDWICH, 'Sentry3::kSandwich'],
        [Blockly.Msg.SENTRY3_YOLO_ORANGE, 'Sentry3::kOrange'],
        [Blockly.Msg.SENTRY3_YOLO_BROCCOLI, 'Sentry3::kBroccoli'],
        [Blockly.Msg.SENTRY3_YOLO_CARROT, 'Sentry3::kCarrot'],
        [Blockly.Msg.SENTRY3_YOLO_HOT_DOG, 'Sentry3::kHotDog'],
        [Blockly.Msg.SENTRY3_YOLO_PIZZA, 'Sentry3::kPizza'],
        [Blockly.Msg.SENTRY3_YOLO_DONUT, 'Sentry3::kDonut'],
        [Blockly.Msg.SENTRY3_YOLO_CAKE, 'Sentry3::kCake'],
        [Blockly.Msg.SENTRY3_YOLO_CHAIR, 'Sentry3::kChair'],
        [Blockly.Msg.SENTRY3_YOLO_COUCH, 'Sentry3::kCouch'],
        [Blockly.Msg.SENTRY3_YOLO_POTTED_PLANT, 'Sentry3::kPottedPlant'],
        [Blockly.Msg.SENTRY3_YOLO_BED, 'Sentry3::kBed'],
        [Blockly.Msg.SENTRY3_YOLO_DINING_TABLE, 'Sentry3::kDiningTable'],
        [Blockly.Msg.SENTRY3_YOLO_TOILET, 'Sentry3::kToilet'],
        [Blockly.Msg.SENTRY3_YOLO_TV, 'Sentry3::kTv'],
        [Blockly.Msg.SENTRY3_YOLO_LAPTOP, 'Sentry3::kLaptop'],
        [Blockly.Msg.SENTRY3_YOLO_MOUSE, 'Sentry3::kMouse'],
        [Blockly.Msg.SENTRY3_YOLO_REMOTE, 'Sentry3::kRemote'],
        [Blockly.Msg.SENTRY3_YOLO_KEYBOARD, 'Sentry3::kKeyboard'],
        [Blockly.Msg.SENTRY3_YOLO_CELL_PHONE, 'Sentry3::kCellPhone'],
        [Blockly.Msg.SENTRY3_YOLO_MICROWAVE, 'Sentry3::kMicrowave'],
        [Blockly.Msg.SENTRY3_YOLO_OVEN, 'Sentry3::kOven'],
        [Blockly.Msg.SENTRY3_YOLO_TOASTER, 'Sentry3::kToaster'],
        [Blockly.Msg.SENTRY3_YOLO_SINK, 'Sentry3::kSink'],
        [Blockly.Msg.SENTRY3_YOLO_REFRIGERATOR, 'Sentry3::kRefrigerator'],
        [Blockly.Msg.SENTRY3_YOLO_BOOK, 'Sentry3::kBook'],
        [Blockly.Msg.SENTRY3_YOLO_CLOCK, 'Sentry3::kClock'],
        [Blockly.Msg.SENTRY3_YOLO_VASE, 'Sentry3::kVase'],
        [Blockly.Msg.SENTRY3_YOLO_SCISSORS, 'Sentry3::kScissors'],
        [Blockly.Msg.SENTRY3_YOLO_TEDDY_BEAR, 'Sentry3::kTeddyBear'],
        [Blockly.Msg.SENTRY3_YOLO_HAIR_DRIER, 'Sentry3::kHairDrier'],
        [Blockly.Msg.SENTRY3_YOLO_TOOTHBRUSH, 'Sentry3::kToothbrush'],
    ]
}

export const vision_obj_card_dict = function () {
    return {
        'Sentry3::kVisionBlob': sentry3_vision_blod_objs(),
        'Sentry3::kVisionYolo': sentry3_vision_yolo_objs()
    }
}

// Sentry3
export const Sentry3Begin = {
    init: function () {
        var mode_objs = [['I2C', 'Wire']]
        var serial_HardwareSelect = Profile.default.serial_HardwareSelect ?? Profile.default.serial_select
        if (serial_HardwareSelect !== undefined) {
            mode_objs = mode_objs.concat(serial_HardwareSelect)
        }
        if (Profile.default.serial_select !== undefined) {
            mode_objs = mode_objs.concat(Profile.default.serial_select)
        }

        mode_objs = Array.from(new Set(mode_objs.map(JSON.stringify))).map(JSON.parse);

        this.appendDummyInput()
            .appendField(
                Blockly.Msg.SENTRY3_BEGIN +
                Blockly.Msg.SENTRY3_NAME
            )
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(
                Blockly.Msg.SENTRY3_PORT
            )
            .appendField(new Blockly.FieldDropdown(mode_objs), 'mode_obj')
            .appendField(Blockly.Msg.SENTRY3_ADDR)
            .appendField(
                new Blockly.FieldDropdown([
                    ['0x60', '0x60']
                ]),
                'addr_obj'
            )
        this.setInputsInline(true)
        this.setPreviousStatement(true, null)
        this.setNextStatement(true, null)
        this.setColour('#EF5411')
        this.setTooltip(Blockly.Msg.SENTRY3_HELP_INIT_TOOLTIP)
    },
}

export const Sentry3LedSetColor = {
    init: function () {
        var led_color = [
            '#fff',
            '#000',
            '#f00',
            '#0f0',
            '#ff0',
            '#00f',
            '#f0f',
            '#0ff',
        ]
        var color_detected = new Blockly.FieldColour('#0000ff')
        color_detected.setColours(led_color).setColumns(4)
        var color_undetected = new Blockly.FieldColour('#ff0000')
        color_undetected.setColours(led_color).setColumns(4)

        this.appendDummyInput()
            .appendField(
                Blockly.Msg.SENTRY3_SET +
                Blockly.Msg.SENTRY3_NAME
            )
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(
                Blockly.Msg.SENTRY3_LED_SET_COLOR
            )
            .appendField(color_detected, 'led_color_obj1')
            .appendField(Blockly.Msg.SENTRY3_LED_SET_COLOR_NOT)
            .appendField(color_undetected, 'led_color_obj2')
            .appendField(Blockly.Msg.SENTRY3_LED_SET_LEVEL)
        this.appendValueInput('level').setCheck([Number])
        this.setInputsInline(true)
        this.setPreviousStatement(true, null)
        this.setNextStatement(true, null)
        this.setColour('#EF5411')
        this.setTooltip(Blockly.Msg.SENTRY3_HELP_LED)
    },
}

// 启用算法
export const Sentry3VisionSetStatus = {
    init: function () {
        this.appendDummyInput()
            .appendField(Blockly.Msg.SENTRY3_SET + Blockly.Msg.SENTRY3_NAME)
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField("  ")
            .appendField(
                new Blockly.FieldDropdown([
                    [Blockly.Msg.SENTRY3_ENABLE, 'Begin'],
                    [Blockly.Msg.SENTRY3_DISABLE, 'End'],
                ]),
                'VisionStatus'
            )
            .appendField(
                Blockly.Msg.SENTRY3_VISION_CN + Blockly.Msg.SENTRY3_VISION_EN
            )
            .appendField(
                new Blockly.FieldDropdown(sentry3_vision_objs()),
                'vision_obj'
            )

        this.setPreviousStatement(true, null)
        this.setNextStatement(true, null)
        this.setColour('#EF5411')
    },
}

export const Sentry3VisionSetParamNum = {
    init: function () {
        this.appendDummyInput()
            .appendField(
                Blockly.Msg.SENTRY3_SET +
                Blockly.Msg.SENTRY3_NAME
            )
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(Blockly.Msg.SENTRY3_VISION_EN)
            .appendField(
                new Blockly.FieldDropdown(sentry3_vision_param_objs()),
                'vision_obj'
            )
        this.appendValueInput('num').setCheck([Number])
            .appendField("  ")
        this.appendDummyInput()
            .appendField(Blockly.Msg.SENTRY3_SET_PARAMNUM)
        this.setPreviousStatement(true, null)
        this.setNextStatement(true, null)
        this.setColour('#EF5411')
    },
}

export const Sentry3VisionColorSetParam = {
    init: function () {
        this.appendDummyInput()
            .appendField(
                Blockly.Msg.SENTRY3_SET +
                Blockly.Msg.SENTRY3_NAME
            )
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(Blockly.Msg.SENTRY3_VISION_EN)
            .appendField(
                new Blockly.FieldDropdown([
                    [
                        Blockly.Msg.SENTRY3_VISION_VISIONCOLOR,
                        'Sentry3::kVisionColor',
                    ],
                ]),
                'vision_obj'
            )
        this.appendDummyInput()
            .appendField(
                "  " + Blockly.Msg.SENTRY3_CENTER + Blockly.Msg.SENTRY3_STATE_VALUE_X
            )
        this.appendValueInput('x').setCheck([Number])
        this.appendDummyInput()
            .appendField(
                Blockly.Msg.SENTRY3_CENTER + Blockly.Msg.SENTRY3_STATE_VALUE_Y
            )
        this.appendValueInput('y').setCheck([Number])
        this.appendDummyInput()
            .appendField(Blockly.Msg.SENTRY3_STATE_VALUE_WIDTH)
        this.appendValueInput('w').setCheck([Number])
        this.appendDummyInput()
            .appendField(Blockly.Msg.SENTRY3_STATE_VALUE_HEIGHT)
        this.appendValueInput('h').setCheck([Number])
        this.appendValueInput('index').setCheck([Number])
            .appendField(Blockly.Msg.SENTRY3_SET_PARAM_GROUP)
        this.setPreviousStatement(true, null)
        this.setInputsInline(true)
        this.setNextStatement(true, null)
        this.setColour('#EF5411')
    },
}

export const Sentry3VisionBlobSetParam = {
    init: function () {
        this.appendDummyInput()
            .appendField(
                Blockly.Msg.SENTRY3_SET +
                Blockly.Msg.SENTRY3_NAME
            )
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(Blockly.Msg.SENTRY3_VISION_EN)
            .appendField(
                new Blockly.FieldDropdown([
                    [
                        Blockly.Msg.SENTRY3_VISION_VISIONBLOB,
                        'Sentry3::kVisionBlob',
                    ],
                ]),
                'vision_obj'
            )
        this.appendDummyInput()
            .appendField("  " + Blockly.Msg.SENTRY3_WEIGHT)
        this.appendValueInput('w').setCheck([Number])
        this.appendDummyInput()
            .appendField(Blockly.Msg.SENTRY3_HEIGHT)
        this.appendValueInput('h').setCheck([Number])
        this.appendDummyInput()
            .appendField(Blockly.Msg.SENTRY3_COLOR)
            .appendField(
                new Blockly.FieldDropdown(sentry3_vision_blod_objs()),
                'lable'
            )
        this.appendValueInput('index').setCheck([Number])
            .appendField(Blockly.Msg.SENTRY3_SET_PARAM_GROUP)
        this.setPreviousStatement(true, null)
        this.setInputsInline(true)
        this.setNextStatement(true, null)
        this.setColour('#EF5411')
    },
}

export const Sentry3VisionSetBlobNum = {
    init: function () {
        this.appendDummyInput()
            .appendField(
                Blockly.Msg.SENTRY3_SET +
                Blockly.Msg.SENTRY3_NAME
            )
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(Blockly.Msg.SENTRY3_VISION_EN)
            .appendField(
                new Blockly.FieldDropdown([
                    [
                        Blockly.Msg.SENTRY3_VISION_VISIONBLOB,
                        'Sentry3::kVisionBlob',
                    ],
                ]),
                'vision_obj'
            )
        this.appendDummyInput()
            .appendField("  " + Blockly.Msg.SENTRY3_EVERY_CLOLR)
        this.appendValueInput('num').setCheck([Number])
        this.setPreviousStatement(true, null)
        this.setNextStatement(true, null)
        this.setInputsInline(true)
        this.setColour('#EF5411')
    },
}

export const Sentry3VisionSetLineNum = {
    init: function () {
        this.appendDummyInput()
            .appendField(
                Blockly.Msg.SENTRY3_SET +
                Blockly.Msg.SENTRY3_NAME
            )
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(Blockly.Msg.SENTRY3_VISION_EN)
            .appendField(
                new Blockly.FieldDropdown([
                    [
                        Blockly.Msg.SENTRY3_VISION_VISIONLINE,
                        'Sentry3::kVisionLine',
                    ],
                ]),
                'vision_obj'
            )
        this.appendDummyInput()
            .appendField("  " + Blockly.Msg.SENTRY3_VISION_MAX_RESULT)
        this.appendValueInput('num').setCheck([Number])
        this.setPreviousStatement(true, null)
        this.setNextStatement(true, null)
        this.setInputsInline(true)
        this.setColour('#EF5411')
    },
}

export const Sentry3VisionSetAprilTagMode = {
    init: function () {
        this.appendDummyInput()
            .appendField(
                Blockly.Msg.SENTRY3_SET +
                Blockly.Msg.SENTRY3_NAME
            )
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(Blockly.Msg.SENTRY3_VISION_EN)
            .appendField(
                new Blockly.FieldDropdown([
                    [
                        Blockly.Msg.SENTRY3_VISION_VISIONAPRILTAG,
                        'Sentry3::kVisionAprilTag',
                    ],
                ]),
                'vision_obj'
            )
        this.appendDummyInput()
            .appendField("  " + Blockly.Msg.SENTRY3_VISION_TAG_CODE)
            .appendField(
                new Blockly.FieldDropdown([
                    ["36H11", 'Sentry3::kVisionModeFamily36H11'],
                    ["16H5", 'Sentry3::kVisionModeFamily16H5'],
                    ["25H9", 'Sentry3::kVisionModeFamily25H9'],
                    ["Circle21H7", '3'],
                    ["Standard41H12", '4'],
                ]),
                'mode'
            )
        this.setPreviousStatement(true, null)
        this.setNextStatement(true, null)
        this.setInputsInline(true)
        this.setColour('#EF5411')
    },
}

export const Sentry3VisionSetBarCodeMode = {
    init: function () {
        this.appendDummyInput()
            .appendField(
                Blockly.Msg.SENTRY3_SET +
                Blockly.Msg.SENTRY3_NAME
            )
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(Blockly.Msg.SENTRY3_VISION_EN)
            .appendField(
                new Blockly.FieldDropdown([
                    [
                        Blockly.Msg.SENTRY3_VISION_VISIONBARCODE,
                        'Sentry3::kVisionBarCode',
                    ],
                ]),
                'vision_obj'
            )
        this.appendDummyInput()
            .appendField("  " + Blockly.Msg.SENTRY3_VISION_TAG_CODE)
            .appendField(
                new Blockly.FieldDropdown([
                    [Blockly.Msg.SENTRY3_ALL, '0'],
                    ["ENA13", '1'],
                    ["Code128", '2'],
                    ["Code39", '3'],
                ]),
                'mode'
            )
        this.setPreviousStatement(true, null)
        this.setNextStatement(true, null)
        this.setInputsInline(true)
        this.setColour('#EF5411')
    },
}


export const Sentry3VisionSetParam = {
    init: function () {
        this.appendDummyInput()
            .appendField(
                Blockly.Msg.SENTRY3_SET +
                Blockly.Msg.SENTRY3_NAME
            )
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(Blockly.Msg.SENTRY3_VISION_EN)
            .appendField(
                new Blockly.FieldDropdown(sentry3_vision_custom()),
                'vision_obj'
            )
            .appendField("  ")
            .appendField(
                new Blockly.FieldDropdown([
                    [
                        Blockly.Msg.SENTRY3_SAVE_DATA,
                        '100',
                    ],
                    [
                        Blockly.Msg.SENTRY3_DEL_DATA,
                        '0',
                    ],
                ]),
                'lable'
            )
            .appendField(
                Blockly.Msg.SENTRY3_SET_ID
            )
        this.appendValueInput('index').setCheck([Number])
        this.setInputsInline(true)
        this.setPreviousStatement(true, null)
        this.setNextStatement(true, null)
        this.setColour('#EF5411')
    },
}

export const Sentry3VisionDetectedCount = {
    init: function () {
        this.appendDummyInput()
            .appendField(
                Blockly.Msg.SENTRY3_NAME
            )
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(Blockly.Msg.SENTRY3_VISION_EN)
            .appendField(
                new Blockly.FieldDropdown(sentry3_vision_objs()),
                'vision_obj'
            )
            .appendField(Blockly.Msg.SENTRY3_DETECTED_NUMBER)
        this.setInputsInline(true)
        this.setOutput(true, null)
        this.setColour('#EAA20A')
    },
}

export const Sentry3GetVisionObjValue = {
    init: function () {
        var _vision_objs = [
            [Blockly.Msg.SENTRY3_VISION_VISIONBLOB, 'Sentry3::kVisionBlob'],
            [
                Blockly.Msg.SENTRY3_VISION_VISIONAPRILTAG,
                'Sentry3::kVisionAprilTag',
            ],
            [
                Blockly.Msg.SENTRY3_VISION_VISIONLEARNING,
                'Sentry3::kVisionLearning',
            ],
            [Blockly.Msg.SENTRY3_VISION_VISIONFACE, 'Sentry3::kVisionFace'],
            [
                Blockly.Msg.SENTRY3_VISION_VISIONYOLO,
                'Sentry3::kVisionYolo',
            ],
            [Blockly.Msg.SENTRY3_VISION_VISIONHANDGESTURE, 'Sentry3::kVisionHandPose']
        ]

        this.appendDummyInput('VisionValue')
            .appendField(Blockly.Msg.SENTRY3_NAME)
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(Blockly.Msg.SENTRY3_VISION_EN)
            .appendField(new Blockly.FieldDropdown(_vision_objs), 'vision_obj')
            .appendField(Blockly.Msg.SENTRY3_VISION_RETURN)
            .appendField(
                new Blockly.FieldDropdown(vision_res_objs()),
                'vision_res_obj'
            )
        this.appendValueInput('index')
            .setCheck([Number])
            .appendField(Blockly.Msg.SENTRY3_VISION_RESULT_1)
        this.appendDummyInput().appendField(Blockly.Msg.SENTRY3_VISION_RESULT_2)
        this.setInputsInline(true)
        this.setOutput(true, Number)
        this.setColour('#EAA20A')
        this.setTooltip(Blockly.Msg.SENTRY3_HELP_GET_VISION_VALUE)
    },
}

export const Sentry3GetVisionObjLineValue = {
    init: function () {
        var _vision_objs = [
            [Blockly.Msg.SENTRY3_VISION_VISIONLINE, 'Sentry3::kVisionLine'],
        ]

        this.appendDummyInput('VisionValue')
            .appendField(Blockly.Msg.SENTRY3_NAME)
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(Blockly.Msg.SENTRY3_VISION_EN)
            .appendField(new Blockly.FieldDropdown(_vision_objs), 'vision_obj')
            .appendField(Blockly.Msg.SENTRY3_VISION_RETURN)
            .appendField(
                new Blockly.FieldDropdown(vision_line_objs()),
                'vision_res_obj'
            )
        this.appendValueInput('index')
            .setCheck([Number])
            .appendField(Blockly.Msg.SENTRY3_VISION_RESULT)
        this.appendDummyInput().appendField(Blockly.Msg.SENTRY3_VISION_RESULT_2)
        this.setInputsInline(true)
        this.setOutput(true, Number)
        this.setColour('#EAA20A')
        this.setTooltip(Blockly.Msg.SENTRY3_HELP_GET_VISION_VALUE)
    },
}

export const Sentry3GetVisionObjStringValue = {
    init: function () {
        var _vision_objs = [
            [Blockly.Msg.SENTRY3_VISION_VISIONQRCODE, 'Sentry3::kVisionQrCode'],
            [Blockly.Msg.SENTRY3_VISION_VISIONBARCODE, 'Sentry3::kVisionBarCode'],
            [Blockly.Msg.SENTRY3_VISION_VISIONOCR, 'Sentry3::kVisionOCR'],
            [Blockly.Msg.SENTRY3_VISION_VISIONLICENCEPLATE, 'Sentry3::kVisionLicensePlate'],
        ]

        this.appendDummyInput('VisionValue')
            .appendField(Blockly.Msg.SENTRY3_NAME)
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(Blockly.Msg.SENTRY3_VISION_EN)
            .appendField(new Blockly.FieldDropdown(_vision_objs), 'vision_obj')
            .appendField(Blockly.Msg.SENTRY3_VISION_RETURN)
            .appendField(
                new Blockly.FieldDropdown(vision_qr_objs()),
                'vision_res_obj'
            )
        this.appendValueInput('index')
            .setCheck([Number])
            .appendField(Blockly.Msg.SENTRY3_VISION_RESULT)
        this.appendDummyInput().appendField(Blockly.Msg.SENTRY3_VISION_RESULT_2)
        this.setInputsInline(true)
        this.setOutput(true, Number)
        this.setColour('#EAA20A')
        this.setTooltip(Blockly.Msg.SENTRY3_HELP_GET_VISION_VALUE)
    },
}

export const Sentry3GetVisionObjColorValue = {
    init: function () {
        var _vision_objs = [
            [Blockly.Msg.SENTRY3_VISION_VISIONCOLOR, 'Sentry3::kVisionColor'],
        ]

        this.appendDummyInput('VisionValue')
            .appendField(Blockly.Msg.SENTRY3_NAME)
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(Blockly.Msg.SENTRY3_VISION_EN)
            .appendField(new Blockly.FieldDropdown(_vision_objs), 'vision_obj')
            .appendField(Blockly.Msg.SENTRY3_VISION_RETURN)
            .appendField(
                new Blockly.FieldDropdown(vision_color_objs()),
                'vision_res_obj'
            )
        this.appendValueInput('index')
            .setCheck([Number])
            .appendField(Blockly.Msg.SENTRY3_VISION_RESULT)
        this.appendDummyInput().appendField(Blockly.Msg.SENTRY3_VISION_RESULT_2)
        this.setInputsInline(true)
        this.setOutput(true, Number)
        this.setColour('#EAA20A')
        this.setTooltip(Blockly.Msg.SENTRY3_HELP_GET_VISION_VALUE)
    },
}

export const Sentry3GetString = {
    init: function () {
        var _vision_objs = [
            [Blockly.Msg.SENTRY3_VISION_VISIONQRCODE, 'Sentry3::kVisionQrCode'],
            [Blockly.Msg.SENTRY3_VISION_VISIONBARCODE, 'Sentry3::kVisionBarCode'],
            [Blockly.Msg.SENTRY3_VISION_VISIONOCR, 'Sentry3::kVisionOCR'],
            [Blockly.Msg.SENTRY3_VISION_VISIONLICENCEPLATE, 'Sentry3::kVisionLicensePlate'],
        ]
        this.appendDummyInput()
            .appendField(
                Blockly.Msg.SENTRY3_NAME
            )
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(Blockly.Msg.SENTRY3_VISION_EN)
            .appendField(new Blockly.FieldDropdown(_vision_objs), 'vision_obj')
            .appendField(Blockly.Msg.SENTRY3_GET_STRING)
        this.appendValueInput('index')
            .setCheck([Number])
            .appendField(Blockly.Msg.SENTRY3_VISION_RESULT_1)
        this.appendDummyInput().appendField(Blockly.Msg.SENTRY3_VISION_RESULT_2)
        this.setInputsInline(true)
        this.setOutput(true, String)
        this.setColour('#EAA20A')
    },
}

export const Sentry3VisionDetectedColor = {
    init: function () {
        this.appendDummyInput('VisionValue')
            .appendField(Blockly.Msg.SENTRY3_NAME
            )
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(Blockly.Msg.SENTRY3_VISION_EN)
            .appendField(
                new Blockly.FieldDropdown([
                    [
                        Blockly.Msg.SENTRY3_VISION_VISIONCOLOR,
                        'Sentry3::kVisionColor',
                    ],
                ]),
                'vision_obj'
            )
            .appendField(Blockly.Msg.SENTRY3_VISION_DETECTED_1)
            .appendField(
                new Blockly.FieldDropdown(
                    vision_obj_card_dict()['Sentry3::kVisionBlob']
                ),
                'vision_card_obj'
            )
        this.appendValueInput('index')
            .setCheck([Number])
            .appendField(Blockly.Msg.SENTRY3_VISION_RESULT_1)
        this.setInputsInline(true)
        this.setOutput(true, Boolean)
        this.setColour('#EAA20A')
        this.setTooltip(Blockly.Msg.SENTRY3_HELP_DETECTED_VISION_VALUE)
    },
}

export const Sentry3VisionDetectedBlob = {
    init: function () {
        this.appendDummyInput('VisionValue')
            .appendField(Blockly.Msg.SENTRY3_NAME
            )
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(Blockly.Msg.SENTRY3_VISION_EN)
            .appendField(
                new Blockly.FieldDropdown([
                    [
                        Blockly.Msg.SENTRY3_VISION_VISIONBLOB,
                        'Sentry3::kVisionBlob',
                    ],
                ]),
                'vision_obj'
            )
            .appendField(Blockly.Msg.SENTRY3_VISION_DETECTED)
            .appendField(
                new Blockly.FieldDropdown(
                    vision_obj_card_dict()['Sentry3::kVisionBlob']
                ),
                'vision_card_obj'
            )
            .appendField(Blockly.Msg.SENTRY3_VISION_BLOCK)
        this.appendValueInput('index')
            .setCheck([Number])
            .appendField(Blockly.Msg.SENTRY3_VISION_RESULT_1)
        this.setInputsInline(true)
        this.setOutput(true, Boolean)
        this.setColour('#EAA20A')
        this.setTooltip(Blockly.Msg.SENTRY3_HELP_DETECTED_VISION_VALUE)
    },
}

export const Sentry3VisionDetectedYolo = {
    init: function () {
        this.appendDummyInput('VisionValue')
            .appendField(Blockly.Msg.SENTRY3_NAME
            )
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(Blockly.Msg.SENTRY3_VISION_EN)
            .appendField(
                new Blockly.FieldDropdown([
                    [
                        Blockly.Msg.SENTRY3_VISION_VISIONYOLO,
                        'Sentry3::kVisionYolo',
                    ],
                ]),
                'vision_obj'
            )
            .appendField(Blockly.Msg.SENTRY3_VISION_DETECTED_1)
            .appendField(
                new Blockly.FieldDropdown(
                    vision_obj_card_dict()['Sentry3::kVisionYolo']
                ),
                'vision_card_obj'
            )
        this.appendValueInput('index')
            .setCheck([Number])
            .appendField(Blockly.Msg.SENTRY3_VISION_RESULT_1)
        this.setInputsInline(true)
        this.setOutput(true, Boolean)
        this.setColour('#EAA20A')
        this.setTooltip(Blockly.Msg.SENTRY3_HELP_DETECTED_VISION_VALUE)
    },
}

export const sentry3_handpose_finger_states = function () {
    return [
        [Blockly.Msg.SENTRY3_HANDPOSE_FINGER_BENT, 'bent'],
        [Blockly.Msg.SENTRY3_HANDPOSE_FINGER_EXTENDED, 'extended'],
        [Blockly.Msg.SENTRY3_HANDPOSE_FINGER_IGNORE, 'ignore'],
    ]
}

export const sentry3_handpose_preset_objs = function () {
    return [
        [Blockly.Msg.SENTRY3_HANDPOSE_ONE, 'A0b00010'],
        [Blockly.Msg.SENTRY3_HANDPOSE_TWO, 'B0b00110'],
        [Blockly.Msg.SENTRY3_HANDPOSE_THREE, 'C0b11100'],
        [Blockly.Msg.SENTRY3_HANDPOSE_FOUR, 'D0b11110'],
        [Blockly.Msg.SENTRY3_HANDPOSE_FIVE, 'E0b11111'],
        [Blockly.Msg.SENTRY3_HANDPOSE_SIX, 'F0b10001'],
        [Blockly.Msg.SENTRY3_HANDPOSE_EIGHT, 'G0b00011'],
        [Blockly.Msg.SENTRY3_HANDPOSE_TEN, 'H0b00000'],
        [Blockly.Msg.SENTRY3_HANDPOSE_YEAN, 'I0b00110'],
        [Blockly.Msg.SENTRY3_HANDPOSE_ROCK, 'J0b00000'],
        [Blockly.Msg.SENTRY3_HANDPOSE_SCISSORS, 'K0b00110'],
        [Blockly.Msg.SENTRY3_HANDPOSE_PAPER, 'L0b11111'],
        [Blockly.Msg.SENTRY3_HANDPOSE_LIKE, 'M0b00001'],
        [Blockly.Msg.SENTRY3_HANDPOSE_OK, 'N0b11100'],
    ]
}

export const Sentry3VisionDetectedHandPoseCustom = {
    init: function () {
        this.appendDummyInput('VisionValue')
            .appendField(Blockly.Msg.SENTRY3_NAME)
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(Blockly.Msg.SENTRY3_VISION_EN)
            .appendField(
                new Blockly.FieldDropdown([
                    [
                        Blockly.Msg.SENTRY3_VISION_VISIONHANDGESTURE,
                        'Sentry3::kVisionHandPose',
                    ],
                ]),
                'vision_obj'
            )
        this.appendDummyInput()
            .appendField(Blockly.Msg.SENTRY3_VISION_DETECTED_1 + Blockly.Msg.SENTRY3_HANDPOSE_THUMB)
            .appendField(
                new Blockly.FieldDropdown(sentry3_handpose_finger_states()),
                'thumb_state'
            )
        this.appendDummyInput()
            .appendField(Blockly.Msg.SENTRY3_HANDPOSE_INDEX)
            .appendField(
                new Blockly.FieldDropdown(sentry3_handpose_finger_states()),
                'index_state'
            )
        this.appendDummyInput()
            .appendField(Blockly.Msg.SENTRY3_HANDPOSE_MIDDLE)
            .appendField(
                new Blockly.FieldDropdown(sentry3_handpose_finger_states()),
                'middle_state'
            )
        this.appendDummyInput()
            .appendField(Blockly.Msg.SENTRY3_HANDPOSE_RING)
            .appendField(
                new Blockly.FieldDropdown(sentry3_handpose_finger_states()),
                'ring_state'
            )
        this.appendDummyInput()
            .appendField(Blockly.Msg.SENTRY3_HANDPOSE_PINKY)
            .appendField(
                new Blockly.FieldDropdown(sentry3_handpose_finger_states()),
                'pinky_state'
            )
        this.appendValueInput('index')
            .setCheck([Number])
            .appendField(Blockly.Msg.SENTRY3_VISION_RESULT_1)
        this.appendDummyInput().appendField(Blockly.Msg.SENTRY3_VISION_RESULT_2)
        this.setInputsInline(true)
        this.setOutput(true, Boolean)
        this.setColour('#EAA20A')
        this.setTooltip(Blockly.Msg.SENTRY3_HELP_DETECTED_VISION_VALUE)
    },
}

export const Sentry3VisionDetectedHandPosePreset = {
    init: function () {
        this.appendDummyInput('VisionValue')
            .appendField(Blockly.Msg.SENTRY3_NAME)
            .appendField(new Blockly.FieldDropdown(sentry_index_objs()), 'SentryIndex')
            .appendField(Blockly.Msg.SENTRY3_VISION_EN)
            .appendField(
                new Blockly.FieldDropdown([
                    [
                        Blockly.Msg.SENTRY3_VISION_VISIONHANDGESTURE,
                        'Sentry3::kVisionHandPose',
                    ],
                ]),
                'vision_obj'
            )
            .appendField(Blockly.Msg.SENTRY3_VISION_DETECTED_1)
            .appendField(
                new Blockly.FieldDropdown(sentry3_handpose_preset_objs()),
                'handpose_preset'
            )
        this.appendValueInput('index')
            .setCheck([Number])
            .appendField(Blockly.Msg.SENTRY3_VISION_RESULT_1)
        this.appendDummyInput().appendField(Blockly.Msg.SENTRY3_VISION_RESULT_2)
        this.setInputsInline(true)
        this.setOutput(true, Boolean)
        this.setColour('#EAA20A')
        this.setTooltip(Blockly.Msg.SENTRY3_HELP_DETECTED_VISION_VALUE)
    },
}